package com.scsystem.xysc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scsystem.xysc.pojo.StoreFollow;
import com.scsystem.xysc.pojo.vo.ReturnResult;
import com.scsystem.xysc.service.StoreFollowService;
import com.scsystem.xysc.mapper.StoreFollowMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
* @author sky
* @description 针对表【store_follow】的数据库操作Service实现
* @createDate 2023-09-16 15:57:10
*/
@Service
public class StoreFollowServiceImpl extends ServiceImpl<StoreFollowMapper, StoreFollow>
    implements StoreFollowService{

    @Resource
    private StoreFollowMapper storeFollowMapper;

    @Override
    public ReturnResult<Boolean> subscribe(Long uid, Long sid) {
        if (uid == null || sid == null) {
            return new ReturnResult<Boolean>().fail("参数不能为空", false);
        }
        StoreFollow storeFollow = new StoreFollow();
        storeFollow.setStoreId(sid);
        storeFollow.setUserId(uid);
        storeFollow.setFollowTime(LocalDateTime.now());
        int insert = storeFollowMapper.insert(storeFollow);
        return insert == 1? new ReturnResult<Boolean>().success("关注成功", true) : new ReturnResult<Boolean>().fail("关注失败", false);
    }

    @Override
    public ReturnResult<Boolean> cancellation(Long uid, Long sid) {
        QueryWrapper<StoreFollow> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", uid)
                        .eq("store_id", sid);
        int delete = storeFollowMapper.delete(queryWrapper);
        return delete == 1? new ReturnResult<Boolean>().success("取消关注成功", true) : new ReturnResult<Boolean>().fail("取消关注失败", false);
    }
}




